import Main from './views/Main';
import Login from './views/Login';
import NotFound from './views/NotFound';
import { Redirect, Route,Switch } from 'react-router-dom';
import {connect} from 'react-redux'

// let isLogin = false  //模拟登录状态
function App(props) {
  console.log('App组件',props);
  return (
    <div className="App">
        <Switch>
          <Redirect from='/' exact to='/admin'/>
          <Route path='/admin' render={()=>{
            if(props.user.isLogin){
              return <Main/>
            }
            return <Redirect to='/login'/>
          }}/>
          <Route path='/login' component={Login}/>
          <Route path='/404' component={NotFound}/>
          <Redirect path='*' to='/404'/>
        </Switch>
    </div>
  );
}

export default connect(({user})=>({user}))(App);
